$(function(){
    var obj = {
        account: '',
        init: function () {
            var that = this;
            that.account = localStorage.getItem('account') || '';
            Ext.onReady(function(){
                if(!that.account){
                    Ext.MessageBox.alert('温馨提示', '账户信息过期，请重新登录！');
                    window.location.replace('./mobileLogin.html');
                    return;
                }
                var tab = new Ext.tab.Panel({
                    width: '100%',
                    items: [
                        {
                            xtype: 'panel',
                            title: '首页',
                            html: '<div class="homePage" style="text-align: center;padding-top: 30px;">' +
                            '<p style="font-size: 18px;">您好，'+(that.account?that.account:'请登录')+ '!</p>' +
                            '<img src="../../images/homePage.png"></div>',
                            //that.account?('您好，'+that.account + '!'):'您好，！',
                            listeners: {
                                render: function() {
                                    //Ext.MessageBox.alert('Rendered One', 'Tab One was rendered.');
                                }
                            }
                        }
                    ]
                });
                new Ext.Viewport({
                    layout:'border',
                    border: false,
                    items:[
                        {
                            region:'north',
                            title: '管理系统',
                            border: false,
                            tabBarHeaderPosition:0,
                            tools: [
                                {
                                    type: 'close',
                                    //text:'登出',
                                    tooltip: '登出',
                                    handler: function (event, toolEl, panelHeader) {
                                        Ext.Msg.confirm( "警告" ,  "确定要登出吗？" ,  function (button) {
                                            if (button == "yes") {
                                                localStorage.removeItem('account');
                                                window.location.replace('./mobileLogin.html');
                                            }
                                        });
                                    }
                                }
                            ]
                        },
                        {region:'south',height:0,border: false,},
                        {
                            region: 'west',
                            width: 200,
                            title: '菜单',
                            border: false,
                            layout: 'accordion',
                            split : true,
                            collapsible: true,
                            layoutConfig: {
                                titleCollapse: true,
                                animate: true,
                                activeOnTop: true 
                            },
                            items : [{
                                title: '企业内部信息管理',
                                xtype: 'treepanel',
                                expanded: true,
                                animate: true,
                                enableDD: false,
                                border: false,
                                rootVisible:false,
                                containerScroll: true,
                                root: {
                                    text: '..',
                                    id: 'root',
                                    children: [{
                                        text: '岗位管理',
                                        id: 'jobManage.html',
                                        leaf: true
                                    }, {
                                        text: '应聘查看',
                                        leaf: true,
                                        id: 'applicantManage.html'
                                    }]
                                },
                                listeners: {
                                    //添加节点点击事件
                                    itemclick: function (v, r, item) {
                                        var n = tab.getComponent(r.raw.id);
                                        if (r.raw.id == 'root') {
                                            return;
                                        }
                                        if (!n) { // 判断是否已经打开该面板
                                            n = tab.add({
                                                'id': r.raw.id,
                                                'title': r.raw.text,
                                                closable: true, // 通过html载入目标页
                                                html: '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="' + r.raw.id + '"></iframe>'
                                            });
                                        }
                                        tab.setActiveTab(n);
                                    }
                                }
                            },{
                                title: '人才市场',
                                xtype: 'treepanel',
                                expanded: true,
                                animate: true,
                                enableDD: false,
                                border: false,
                                rootVisible:false,
                                containerScroll: true,
                                root: {
                                    text: '..',
                                    id: 'root',
                                    children: [{
                                        text: '人才登记查询',
                                        id: 'applicantMsgList.html',
                                        leaf: true
                                    }]
                                },
                                listeners: {
                                    //添加节点点击事件
                                    itemclick: function (v, r, item) {
                                        var n = tab.getComponent(r.raw.id);
                                        if (r.raw.id == 'root') {
                                            return;
                                        }
                                        if (!n) { // 判断是否已经打开该面板
                                            n = tab.add({
                                                'id': r.raw.id,
                                                'title': r.raw.text,
                                                closable: true, // 通过html载入目标页
                                                html: '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="' + r.raw.id + '"></iframe>'
                                            });
                                        }
                                        tab.setActiveTab(n);
                                    }
                                }
                            }, {
                                title: '系统管理',
                                xtype: 'treepanel',
                                expanded: true,
                                animate: true,
                                enableDD: false,
                                border: false,
                                containerScroll: true,
                                rootVisible:false,
                                root: {
                                    text: '..',
                                    id: 'root2',
                                    children: [{
                                        text: '新用户注册',
                                        id: 'register.html',
                                        leaf: true
                                    },{
                                        text: '修改密码',
                                        id: 'resetPassword.html',
                                        leaf: true
                                    }]
                                },
                                listeners: {
                                    //添加节点点击事件
                                    itemclick: function (v, r, item) {
                                        var n = tab.getComponent(r.raw.id);
                                        if (r.raw.id == 'root') {
                                            return;
                                        }
                                        if (!n) { // 判断是否已经打开该面板
                                            n = tab.add({
                                                'id': r.raw.id,
                                                'title': r.raw.text,
                                                closable: true, // 通过html载入目标页
                                                html: '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="' + r.raw.id + '"></iframe>'
                                            });
                                        }
                                        tab.setActiveTab(n);
                                    }
                                },
                            }]
                        },
                        {region:'east',width:0,border: false,},
                        {
                            region:'center',
                            border: false,
                            layout: 'fit',
                            margin: '5 5 0 0',
                            items: [tab]
                        }
                    ]
                });
            });
        }
    };
    obj.init();
});